import {decrypt, encrypt} from "./mm";
import store from "../store";

export function setToken(token){
    localStorage.setItem('token', token);
}
export function getToken(){
    return localStorage.getItem('token');
}
export function removeToken(){
    localStorage.removeItem('token');
    localStorage.removeItem('staffInfo');
}
export function removeStaffInfo(){
    localStorage.removeItem('staffInfo');
    localStorage.removeItem('token');
}

export function setStaffInfo(staffInfo){
    if(staffInfo){
        localStorage.setItem('staffInfo',encrypt(JSON.stringify(staffInfo)));
        store.commit('SetUserInfo',staffInfo);
        getConfig();
        return staffInfo;
    }
}

export function getStaffInfo(){
    let staffInfoCiphertext = localStorage.getItem('staffInfo');
    if(staffInfoCiphertext) {
        store.commit('SetUserInfo',JSON.parse(decrypt(staffInfoCiphertext)));
        getConfig();
    }
}

export function getConfig(){
    store.dispatch('config/selectPrescriptionFun');
}


export function endLoad(){
    store.commit("EndLoad");
}
export function startLoad(){
    store.commit("StartLoad");
}
